#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS 1
#endif

#include<iostream>
#include<vector>
using namespace std;
/*
http://ybt.ssoier.cn:8088/problem_show.php?pid=1294
*/
void ac1(){
	int n,m;
	cin>>n>>m;
	vector<long long>w(n+1,0),c(n+1,0),dp(m+1,0);
	for(int i=1;i<=n;i++)
		cin>>w[i]>>c[i];
	for(int i=1;i<=n;i++)
		for(long long j=m;j>=w[i];j--)
			dp[j]=max(dp[j],dp[j-w[i]]+c[i]);
	cout<<dp[m];
}

int main() {
	ac1();
	return 0;
}
